package com.citrix.gs.util.beacon.job;

import java.text.MessageFormat;

import com.citrix.gs.util.RepositoryDeployer;
import com.citrix.gs.util.beacon.BeaconJobType;
import com.citrix.gs.util.beacon.JobConfig;
import com.citrix.gs.util.common.Config;

public class BeaconToolsetJob extends BeaconJob implements Deployable {

    public BeaconToolsetJob(RepositoryDeployer deployer) {
        super(deployer);
        this.jobType = BeaconJobType.Toolset;
        this.jobName = this.jobType.name() + "-" + repo.getName();
        this.tempFile = jobType.name().toLowerCase() + "_template.xml";
    }

    @Override
    public void add() {
        
        String clientName = JobConfig.getTestClientPrefix() + "-" + jobName ;
        String projectPath = MessageFormat.format(Config.me().getProperty("test.tools.viewmap"), clientName);
        
        
        if(beforeAdd() && editPerforceSCM(Config.me().getProperty("platform.perforce.username"), 
                Config.me().getProperty("platform.perforce.ticket"), 
                Config.me().getProperty("platform.perforce.server"), clientName, projectPath) // Edit SCM(perforce part)
                && editAssignedNode() // Edit assignedNode
                && editUpstreamJob(BeaconJobType.Config.name())// watch upstream job
                && editNodeStalkerBuildWrapper() // use same workspace with src job
                && createJob() // create job
                ) {
            
        } else {
            
            
        }
        
    }

    @Override
    public void move() {
        if(beforeMove() && updateClient() && updateProjectPath() && moveJob()) {
            
        } else {
            
        }
    }

    public boolean updateProjectPath(){
        
        return updateProjectPath("BeaconToolset_TEST", "BeaconToolset");
    }

}
